package com.kun.service.impl;

import com.kun.entity.User;
import com.kun.mapper.UserMapper;
import com.kun.service.UserService;
import com.kun.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author SunKun
 * @since 2021-06-14
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User queryUser(User user) {
        User tUser = userMapper.queryUsername(user.getUsername());
        if(!ObjectUtils.isEmpty(tUser))
            //经过加盐加密然后进行比较
            if(MD5Utils.getSaltVerifyMD5(user.getPassword(),tUser.getPassword()))
                return tUser;
            else
                throw new RuntimeException("密码不正确！");

        throw new RuntimeException("账号不正确!");
    }
}
